#include <set>
#include <cstdlib>

#include "../utils.h"

using namespace std;

void test_multiset()
{
    multiset<int> ms;
    int size=21;
    int maxvalue=11;
    int valuetofind=7;
    int valuetoreplace[2]={3,9};
    
    for (int i=0; i<size; ++i)
    {
        ms.insert(random() % maxvalue);
    }
    
    print_elements(ms, "All elements in multiset:");
    
    //Get all elements out equial to the provided value;
    if (ms.end() != ms.find(valuetofind))
    {
        cout << "all elements equal to " << valuetofind << " are:" << endl;
        for (multiset<int>::const_iterator it=ms.lower_bound(valuetofind);
             it != ms.upper_bound(valuetofind);
             ++it)
        {
            cout << *it << " ";
        }
        cout << endl;  
    }
    
    //Replace all the elements that equal to some value and replace them to new value;
    //no direct way to change the value of the elements in set/multiset
    int numReplaced = ms.erase(valuetoreplace[0]);
    for (int i=0; i<numReplaced; ++i)
    {
        ms.insert(valuetoreplace[1]);
    }
    
    print_elements(ms, "all elememts after replace");
}

void test_set_multiset()
{
    test_multiset();
}
